﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Blog.TemplateEngine.Helpers;

namespace Blog.TemplateEngine
{
    public class Context
    {
        private Dictionary<string, object> mValues;
        private List<Dictionary<string, object>> mStack;

        public Context()
        {
            mValues = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
            mStack = new List<Dictionary<string, object>>();
        }

        public bool ContainsKey(string key)
        {
            return mValues.ContainsKey(key);
        }

        public object this[string key]
        {
            get
            {
                if(mValues.ContainsKey(key))
                    return mValues[key];
                return string.Empty;
            }
            set
            {
                mValues[key] = value;
            }
        }

        public void Push()
        {
            mStack.Push(new Dictionary<string, object>(mValues, StringComparer.InvariantCultureIgnoreCase));
        }

        public void Pop()
        {
            mValues = mStack.Pop();
        }
    }
}
